package net.xdclass.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShardingTableConfig {
    /**
     * 存储数据库位置编号
     */
    private static final List<String> tablePrefix = new ArrayList<>();
    /**
     * 数据库分片前缀
     */
    private static Random random = new Random();
    static {
        tablePrefix.add("0");
        tablePrefix.add("a");
    }

    /**
     * 获取随机前缀
     * @return
     */
//    public static String getRandomDBPrefix(){
//        int index = random.nextInt(tablePrefix.size() );
//        return tablePrefix.get(index);
//    }

    public static String getRandomTablePrefix(String code) {
        int hashCode = code.hashCode();
        int index = Math.abs(hashCode) % tablePrefix.size();
        return tablePrefix.get(index);
    }
}
